#!/usr/bin/env python
# -*- coding: utf-8 -*-


import sys
import os
import re

RE_PREFIX = '^\s*'

# 将python不能执行的shell命令对换为相应的python命令
SH_TO_PY = dict(cd=os.chdir)
RE_SH_TO_PY = {}

for k, v in SH_TO_PY.iteritems():
    RE_SH_TO_PY[k] = re.compile(RE_PREFIX + k + '\s+')

def run(cmd):
    for cmd_, re_ in RE_SH_TO_PY.iteritems():
        if re_.match(cmd):
            cmd = re_.sub('',cmd)
            SH_TO_PY[cmd_](cmd)
            break
    else:
        os.system(cmd)


def main():
    cmd = raw_input('> ')
    while cmd.strip().lower() != 'exit':
        run(cmd)
        cmd = raw_input('> ')

if __name__ == '__main__':
    try:
        main()
    except (EOFError, KeyboardInterrupt):
        sys.exit(0)
